﻿using AutoMapper;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using SassModule.Contracts;
using SassModule.ViewModel;
using System;

namespace SassModule.Controllers
{
    /// <summary>
    /// TokenController
    /// </summary>
    [ApiController]
    [Route("Sass/[controller]")]
    public class TokenController : ControllerBase
    {
        private readonly ILogger _logger;
        private readonly IWebHostEnvironment _env;
        private readonly IUserService _service;
        private readonly IMapper _mapper;
        /// <summary>
        /// ctor
        /// </summary>
        /// <param name="mapper"></param>
        /// <param name="logger"></param>
        /// <param name="env"></param>
        /// <param name="service"></param>
        public TokenController(IMapper mapper,ILogger<SassController> logger, IWebHostEnvironment env, IUserService service)
        {
            _logger = logger;
            _env = env;
            _service = service;
            _mapper = mapper;
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public IActionResult Login(TokenViewModel info)
        {
            var result = _service.Login(info);
            if (!string.IsNullOrEmpty(result.Msg))
            {
                return Ok(new ResponseData(result.Msg, null));
            }
            return Ok(new ResponseData(null,result));
        }
    }
}
